package com.vpen.controller;

import com.vpen.base.BaseCode;
import com.vpen.base.BaseMsg;
import com.vpen.base.BaseResult;
import com.vpen.exception.IException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @version: 1.0
 * @author: Vpen
 * @date: 2021/10/2 22:20
 * @content:
 */
@Api(tags = "异常")
@RestController
@RequestMapping("${api.prefix.url}/api/exception")
public class MyExceptionController {

    @GetMapping
    @ApiOperation("成功")
    public void getException(){
        throw new IException("200","成功");
    }

    @GetMapping("/e")
    @ApiOperation("失败")
    public void getException2(){
        throw new IException(BaseCode.ERROR);
    }

    @GetMapping("/ok")
    @ApiOperation("返回")
    public BaseResult<Boolean> getResultOk(){
        return BaseResult.ok();
    }

    @GetMapping("/error")
    public BaseResult<Boolean> getResultError(){
        return BaseResult.error();
    }

    @GetMapping("/string")
    public BaseResult<String> getResultString(){
        String str = "你好";
        return BaseResult.ok(str);
    }

    @GetMapping("/test")
    public BaseResult<BaseMsg> getResultTest(){
        BaseMsg baseMsg = new BaseMsg();
        baseMsg.setCode("130");
        baseMsg.setMessage("sssfsdf");
        return BaseResult.ok(baseMsg);
    }


    @GetMapping("/test2")
    public BaseResult<?> getResultTest2(){
        return BaseResult.auto(false, LocalDateTime.now(),"获取时间失败");
    }

    @GetMapping("/test3")
    public BaseResult<?> getResultTest3(){
        return BaseResult.auto(true, LocalDateTime.now(),"获取时间失败");
    }

    @GetMapping("/test4")
    public BaseResult<Boolean> getResultTest4(){
        return BaseResult.auto(true);
    }






}
